﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.MainPlans;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week2.Mainplan_CRUD
{
    public class GetMainplanHandelr : IRequestHandler<GetMainplanCommand, Result>
    {
        /// <summary>
        /// 获取需要修改的主生产计划数据
        /// </summary>
        /// <param name="mainpalanRepository"></param>
        public GetMainplanHandelr(IBaseRepository<ShowMainPlanDTO> mainpalanRepository)
        {
            MainpalanRepository = mainpalanRepository;
        }

        public IBaseRepository<ShowMainPlanDTO> MainpalanRepository { get; set; }
        public async Task<Result> Handle(GetMainplanCommand request, CancellationToken cancellationToken)
        {
            var result=new Result() { Code=(int)CommonErrorCodes.Update};
            var sql = $"select * from mainpalans as a join mainplandetails as b on a.MainplanNum =b.MainplanNum  where MainplanId={request.MainplanId};";
            var list = MainpalanRepository.GetAll(sql);
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
